// packageB/mycomponent/groupListPopup/groupListPopup.js
const app = getApp();
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    item: {
      type: Array
    },
    info: {
      type: Object
    },
    storeId: null,
    plu: {
      type: String
    }, 
  },
  observers: {},
  /**
   * 组件的初始数据
   */
  data: {
    show: false,
    teamInfo: [],
    uid: '',
    shareModel: {
      title: '',
      path: '',
      imageUrl: '',
      fromButton: ''
    }
  },
  lifetimes: {
    // 生命周期函数，可以为函数，或一个在methods段中定义的方法名
    attached() {
      try {
        let uid = wx.getStorageSync('yz_uid');
        this.setData({
          uid
        });
      } catch (error) {
        console.log(error);
      }
    },
    moved() {},
    detached() {},
  },
  /**
   * 组件的方法列表
   */
  methods: {
    tapOverlay() {
      this.setData({
        show: false
      });
    },
    getAllTeam(e) {
      let id = this.data.info.id;
      let PLU = 'fight-groups';
      if(this.data.plu == 'ywmGroup') PLU = 'ywm-fight-groups';
      let urlStr = app.getNetAddresss(`plugin.${PLU}.frontend.controllers.fight-groups-goods.all-team`);
      app._getNetWork({
        url: urlStr,
        data: {
          id: id
        },
        success: (resdata) => {
          var res = resdata.data;
          if (res.result == 1) {
            this.setData({
              isLoadMore: true,
              total_page: res.data.last_page,
              teamInfo: res.data.data,
              show: true
            });
            if (!this.data.total_page) {
              this.setData({
                total_page: 0,
              });
            }
          } else {
            wx.showToast({
              icon: "none",
              title: res.msg,
              duration: 1500,
            });
          }
        },
      });
    },
    // 加入该团按钮
    clickAdd(e) {
      // let _id = e.target.dataset.id || e.currentTarget.dataset.id;
      let status = e.target.dataset.item || e.currentTarget.dataset.item;
      let _team_id = e.target.dataset.id || e.currentTarget.dataset.id;

        let that = this;
        let goods = [];
        goods.push(that.data.goodsId);
        let urlStr = app.getNetAddresss("from.div-from.isDisplay");
        urlStr += "&goods_ids=" + JSON.stringify(goods);
        app._getNetWork({
          showToastIn: false,
          url: urlStr,
          success: (resdata)=> {
            var res = resdata.data;
            if (res.result == 1) {
              if (res.data.status && !res.data.member_status) {
                wx.showModal({
                  title: "提示",
                  content: "购买此商品,请补充您的个人信息",
                  success(res) {
                    if (res.confirm) {
                      //保税真实信息添加
                      wx.navigateTo({
                        url: "/packageB/member/address/myinfo/myinfo?tag=group" + "&activityId=" + that.data.activityId,
                      });
                    }
                  },
                });
              } else {
                if(this.data.plu == 'ywmGroup'){
                  wx.navigateTo({
                    url: "/packageB/member/group/GroupDetail/GroupDetail?id=" + _team_id + "&plu=ywm"
                  });
                  return;
                }
                wx.navigateTo({
                  url: "/packageB/member/group/GroupDetail/GroupDetail?id=" + _team_id + "&store_id=" + that.properties.storeId,
                });
              }
            } else {
              wx.showToast({
                icon: "none",
                title: res.msg,
                duration: 1500,
              });
            }
          },
          fail: function (res) {},
        });
      
    },
  }
});